{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c8e9c5a9-44fb-4c4e-90ef-d5e52d474828",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 数学符号计算\n",
    "from sympy import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "586a368e-53dd-439c-9996-1913d9a7af46",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "190\n"
     ]
    }
   ],
   "source": [
    "# use eval 解析数学表达式\n",
    "x = 10\n",
    "y = 20\n",
    "result = eval(\"x * y - x\")\n",
    "print(result)  # 输出：190"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "e269d3c5-3436-4f4e-a144-e05b3f753aa9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.5\n"
     ]
    }
   ],
   "source": [
    "print(eval(\"(1+2)/6\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "33aedf25-a51c-4e74-bd74-4eb97497d56e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1963.4954084936207"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "# 一个圆的面积\n",
    "eval(\"math.pi * pow(25, 2)\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
